package com.service.business.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.business.coupon.controller.rep.MemberCouponPageRep;
import com.service.business.coupon.controller.req.MemberCouponPageReq;
import com.service.business.product.controller.rep.ProductHrComboPageRep;
import com.service.business.product.service.MemberCouponService;
import com.service.business.support.Language;
import com.service.business.support.SessionUtil;
import com.service.business.utils.DateUtil;
import com.service.core.rest.response.CommonPageRep;
import com.service.core.rest.response.PageResponse;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.mapper.MemberCouponMapper;
import com.service.dao.model.MemberCoupon;
import com.service.dao.model.ProductHrCombo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class MemberCouponServiceImpl extends ServiceImpl<MemberCouponMapper, MemberCoupon> implements MemberCouponService {

    @Autowired
    private SessionUtil sessionUtil;
    /**
     * 获取当前用户对应该产品的所有有效优惠券
     *
     * @param memberId
     * @param productId
     * @return
     */
    @Override
    public List<MemberCoupon> listByMemberAndProductId(Integer memberId, Integer productId) {
        return baseMapper.listByMemberAndProductId(memberId, productId);
    }

    /**
     * 分页获取用户有效优惠券
     *
     * @param pageRequest
     * @return
     */
    @Override
    public CommonPageRep<MemberCoupon> pageMemberCouponById(MemberCouponPageReq pageRequest) {
        Integer memberId = sessionUtil.getUser().getUserId();
        Page<MemberCoupon> page = PageHelper.startPage(pageRequest.getPageNo(), pageRequest.getPageSize());
        List<MemberCoupon> couponList = new ArrayList<>();
        if(!ObjectUtils.isEmpty(memberId)){
            couponList = baseMapper.pageMemberCouponById(memberId);
        }
        return CommonPageRep.buildResultRep(page, couponList);
    }
}
